package com.clothing.customization.controller.admin;

import com.clothing.customization.common.api.Result;
import com.clothing.customization.entity.DesignerQualification;
import com.clothing.customization.entity.DesignerReview;
import com.clothing.customization.entity.DesignerSchedule;
import com.clothing.customization.service.DesignerQualificationService;
import com.clothing.customization.service.DesignerReviewService;
import com.clothing.customization.service.DesignerScheduleService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api/admin/designer")
@RequiredArgsConstructor
public class DesignerManagementController {

    private final DesignerQualificationService qualificationService;
    private final DesignerScheduleService scheduleService;
    private final DesignerReviewService reviewService;

    // 资质审核相关接口
    @GetMapping("/qualification/list")
    public Result<Map<String, Object>> getQualificationList(@RequestParam Map<String, Object> params) {
        Page<DesignerQualification> page = qualificationService.findByPage(params);
        return Result.success(Map.of(
            "list", page.getContent(),
            "total", page.getTotalElements()
        ));
    }

    @PostMapping("/qualification/{id}/approve")
    public Result<Void> approveQualification(@PathVariable Long id) {
        qualificationService.approve(id);
        return Result.success();
    }

    @PostMapping("/qualification/{id}/reject")
    public Result<Void> rejectQualification(@PathVariable Long id) {
        qualificationService.reject(id);
        return Result.success();
    }

    // 日程管理相关接口
    @GetMapping("/schedule/list")
    public Result<Map<String, Object>> getScheduleList(@RequestParam Map<String, Object> params) {
        Page<DesignerSchedule> page = scheduleService.findByPage(params);
        return Result.success(Map.of(
            "list", page.getContent(),
            "total", page.getTotalElements()
        ));
    }

    @PostMapping("/schedule/{id}/cancel")
    public Result<Void> cancelSchedule(@PathVariable Long id) {
        scheduleService.cancel(id);
        return Result.success();
    }

    // 评价管理相关接口
    @GetMapping("/review/list")
    public Result<Map<String, Object>> getReviewList(@RequestParam Map<String, Object> params) {
        Page<DesignerReview> page = reviewService.findByPage(params);
        return Result.success(Map.of(
            "list", page.getContent(),
            "total", page.getTotalElements()
        ));
    }

    @PostMapping("/review/{id}/approve")
    public Result<Void> approveReview(@PathVariable Long id) {
        reviewService.approve(id);
        return Result.success();
    }

    @PostMapping("/review/{id}/reject")
    public Result<Void> rejectReview(@PathVariable Long id) {
        reviewService.reject(id);
        return Result.success();
    }
} 